package com.jtjrenren.android.taxi.passenger.core.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.bean.AddressInfo;
import com.jtjrenren.android.taxi.passenger.base.BaseRcyAdapter;

/**
 * Created by Administrator on 2016/1/13.
 */
public class PlaceListAdapter extends BaseRcyAdapter<AddressInfo> {
    public interface ItemClickListener{
        void onItemClick(AddressInfo info);
    }

    private ItemClickListener listener;

    public void setListener(ItemClickListener listener) {
        this.listener = listener;
    }

    public PlaceListAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_place_choose, parent, false);
        return new PlaceViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        PlaceViewHolder placeViewHolder= (PlaceViewHolder) holder;
        AddressInfo info = list.get(position);
        placeViewHolder.tv_name.setText(info.getName());
        placeViewHolder.tv_addr.setText(info.getAddr());
    }

    class PlaceViewHolder extends RecyclerView.ViewHolder {
        TextView tv_name, tv_addr;

        public PlaceViewHolder(View itemView) {
            super(itemView);

            tv_name = (TextView) itemView.findViewById(R.id.item_place_name);
            tv_addr = (TextView) itemView.findViewById(R.id.item_place_addr);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener!=null)
                        listener.onItemClick(list.get(getAdapterPosition()));
                }
            });
        }
    }
}
